package com.yanqu.road.logic.activity.hotpotjump.game.choose;

import com.yanqu.road.logic.activity.hotpotjump.game.JumpBoardGrid;
import com.yanqu.road.logic.activity.hotpotjump.game.eJumpDirection;

import java.util.*;

/**
 * 2 一条直线上被跳跃攻击的两个及以上敌人所在点
 */
public class HotpotJumpSkillChoose2 extends HotpotJumpSkillChoose {
    @Override
    public List<List<JumpBoardGrid>> chooseGrid() {
        List<List<JumpBoardGrid>> result = new ArrayList<>();

        Map<JumpBoardGrid, Set<eJumpDirection>> chooseGridsMap = new HashMap<>();
        for (int i = 0; i < gameLogic.getPathUnitGrids().size(); i++) {
            JumpBoardGrid iterGrid = gameLogic.getPathUnitGrids().get(i);
            for (int i1 = i + 1; i1 < gameLogic.getPathUnitGrids().size(); i1++) {
                JumpBoardGrid otherGrid = gameLogic.getPathUnitGrids().get(i1);
                eJumpDirection direction = iterGrid.calcTargetDirection(otherGrid);
                if (direction != eJumpDirection.None) {
                    Set<eJumpDirection> directions = chooseGridsMap.get(iterGrid);
                    if (directions == null) {
                        directions = new HashSet<>();
                        chooseGridsMap.put(iterGrid, directions);
                    }
                    directions.add(direction);
                }
            }
        }

        for (Map.Entry<JumpBoardGrid, Set<eJumpDirection>> entry : chooseGridsMap.entrySet()) {
            JumpBoardGrid grid = entry.getKey();
            Set<eJumpDirection> directions = entry.getValue();
            for (eJumpDirection direction : directions) {
                List<JumpBoardGrid> grids = gameLogic.calcRangeGrids(grid, skillRange, direction);
                boolean alreadyHave = false;
                for (List<JumpBoardGrid> list : result) {
                    if (list.containsAll(grids)) {
                        alreadyHave = true;
                        break;
                    }
                }
                if (!alreadyHave) {
                    result.add(grids);
                }
            }
        }

        return result;
    }
}
